package com.ilas.controller;

import com.ilas.aspect.DataSource;
import com.ilas.config.DynamicDataSourceContextHolder;
import com.ilas.entity.BizUser;
import com.ilas.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>${Description}</p>
 *
 * @author luzck
 * @date 2021/4/1 9:42
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("all")
    public List<BizUser> findAll(){

        return userService.getList();
    }
    @RequestMapping("all2")
    @DataSource()
    public List<BizUser> findAll2(){
        return userService.getList2();
    }

    @RequestMapping("all3")
    @DataSource("tenantTest")
    public List<BizUser> findAll3(){
        return userService.getList2();
    }

    @RequestMapping("insert")
    public String insert(){
        DynamicDataSourceContextHolder.setDataSourceKey("tenantTest");
        BizUser user = new BizUser();
        user.setName("luzck");
        user.setUsername("luzck");
        user.setPassword("123");
        userService.insertUser(user);

        return "ok";
    }

    @RequestMapping("insert2")
    @DataSource()
    public String insert2(){
        BizUser user = new BizUser();
        user.setName("luzck2");
        user.setUsername("luzck2");
        user.setPassword("123");
        userService.insertUser(user);
        return "ok";
    }

}
